﻿/*
 * Создан: Оникийчук Антон Игоревич
 * Компания: ООО "ИМСАТ"
 * Дата создания: 29.01.2009
 * Время создания: 16:16
 * Emal разработчика: onikiychuka@gmail.com
 */
namespace IMSAT.OFTD.DOM
{
    /// <summary>
    /// Description of LinkConnectionPoint.
    /// </summary>
    public class LinkConnectionPoint
    {
        #region Delegates

        public delegate void ConnectedDelegate(LinkConnectionPoint point, Element item);

        public delegate bool ConnectionFilterDelegate(LinkConnectionPoint point, Element item);

        #endregion

        private Element _connetedItem;

        private string _name = "";

        private Element _owner;

        public LinkConnectionPoint()
        {
            Connection += delegate { return true; };
            Connected += delegate { };
        }

        public string Name
        {
            get { return _name; }
        }

        public Element Owner
        {
            get { return _owner; }
        }

        public Element ConnetedItem
        {
            get { return _connetedItem; }
        }

        public event ConnectionFilterDelegate Connection;

        public event ConnectedDelegate Connected;

        public bool Connect(Element item)
        {
            if (item == _connetedItem)
                return true;
            if (item == _owner)
                return false;
            if (Connection(this, item))
            {
                _connetedItem = item;
                Connected(this, _connetedItem);
                return true;
            }
            return false;
        }
    }
}